package io.renren.modules.project.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.modules.project.dao.ProPlanDao;
import io.renren.modules.project.entity.ProPlanEntity;
import io.renren.modules.project.service.ProPlanService;
import io.renren.modules.sys.entity.SysLogEntity;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.Map;

@Service
public class ProPlanServiceImpl extends ServiceImpl<ProPlanDao, ProPlanEntity> implements ProPlanService {

    private final ProPlanDao proPlanDao;

    public ProPlanServiceImpl(ProPlanDao proPlanDao) {
        this.proPlanDao = proPlanDao;
    }

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        String projectName = (String)params.get("projectName");

//        IPage<ProPlanEntity> page = this.page(
//                new Query<ProPlanEntity>().getPage(params),
//                new QueryWrapper<ProPlanEntity>().like(StringUtils.isNotBlank(projectName),"project_name", projectName)
//                        .orderByDesc("id")
//        );

        IPage<ProPlanEntity> page = proPlanDao.getProList(new Query<ProPlanEntity>().getPage(params), params);
        return new PageUtils(page);
    }

    @Override
    public void deleteBatch(int[] ids) {
        // 要么做关联删除；要么做查询做删除保护
        // todo: 查询项目的开发数据和测试数据是否存在，存在则不允许删除

        this.removeByIds(Arrays.asList(ids));
    }
}
